package model;

import java.util.Observable;

import android.util.Log;

public class Snippet  extends Observable{
	
	private String _id;
	
	private Dimension _dimension;
	private Coordinate _coordinate;
	
	/* in order to show a snippet on the screen when it is being viewed from the side, 
	 * you need to know 4 corners of the shape it is shown in.
	 */	
	private Coordinate[] _corners; 	
	
	public Coordinate[] getCorners() {
		return _corners;
	}

	public void setCorners(Coordinate[] corners) {
		_corners = corners;
	}

	private DisplayType _displayType; 
	private Boolean _information; // for now a boolean that indicates red or green, expand in other sprint
	
	public Dimension getDimension() {
		return _dimension;
	}

	public void setDimension(Dimension dimension) {
		if(this._dimension == null)
			this._dimension = dimension;
	}

	public Coordinate getCoordinate() {
		return _coordinate;
	}

	public void setCoordinate(Coordinate coordinate) {
		if(this._coordinate == null)
			this._coordinate = coordinate;
	}

	public DisplayType getDisplayType() {
		return _displayType;
	}

	public void setDisplayType(DisplayType displayType) {
		if(this._displayType == null)
			this._displayType = displayType;
	}

	public boolean isInformation() {
		return _information;
	}

	public void setInformation(Boolean information) {
		if(this._information == null)
			this._information = information;
	}
	
	public String getID() {
		return _id;
	}

	public void setID(String id) {
		if(this._id == null)
			this._id = id;
	}

	public Snippet(String id, Coordinate coord, Dimension dimension ,Boolean information, int type)
	{
		setID(id);
		setCoordinate(coord);
		setDimension(dimension);

		//Coordinate[] tempCorners = { new Coordinate(x,y), new Coordinate(x,y+height), new Coordinate(x+width, y), new Coordinate(x+width,y+height) };
		//setCorners(tempCorners);
		
		setInformation(information);		
		setDisplayType(DisplayType.values()[type]);
	}
	
	public Snippet(String id, Coordinate[] corners, Boolean information, int type)
	{
		setID(id);
		setCorners(corners);
		setInformation(information);		
		setDisplayType(DisplayType.values()[type]);
	}
	
	@Override
	public void notifyObservers() 
	{
		setChanged();
		super.notifyObservers();
	}
	
	@Override
	public void notifyObservers(Object data) {
		 setChanged();
		super.notifyObservers(data);
	}

	public Snippet update(Snippet snippet) {
		this._coordinate = snippet.getCoordinate();
		this._information = snippet.isInformation();
		this._dimension = snippet.getDimension();
		Log.d("SNIPVIEW", "snippet heeft zoveel aantal observers: " + this.countObservers());
		this.notifyObservers();
		return null;
	}

	@Override
	public String toString() 
	{
		return String.format("ID: %s\nCoord: {%d ; %d}\nDimension: {%d ; %d}\nDisplayType: %s\nInfo: %s", _id, _coordinate.getX(), _coordinate.getY(), _dimension.getWidth(), _dimension.getHeight(), _displayType.toString(), _information.toString());
	}
	
}
